package cn.tedu.collection;/**
 * @Author 金帮嘉诚 @Date 2021-06-21 星期一 14:12
 */
/*本类用于测试List接口的子类ArrayList*/

import sun.plugin.javascript.navig.JSObjectResolver;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.ListIterator;

/**知识点
 * ArrayList的方法
 * get
 * contains
 * indexOf
 * lastIndexOf
 * remove 根据下标删除，和根据元素删除，根据元素删除时如果元素是int类型，要用Integer.valueOf(e)
 *
 *
 * */
public class TestArrayList {
    public static void main(String[] args) {
        //
        //初始长度10 扩容一次1.5倍，>>右移符号，相当于除以2
        ArrayList<Integer> list=new ArrayList<Integer>();

        //
        list.add(100);//
        list.add(200);
        list.add(300);
        list.add(400);
        list.add(200);
//        list.clear();
//        System.out.println("list = " + list);

        System.out.println("list.contains(100) = " + list.contains(100));//
        System.out.println("list.get(1) = " + list.get(1));//
        System.out.println("list.indexOf(200) = " + list.indexOf(200));//
        System.out.println("list.lastIndexOf(200) = " + list.lastIndexOf(200));//

        /*注意，此种写法会报错*/
//        System.out.println("list.remove(300) = " + list.remove(300));//会报错
//        System.out.println("list.remove(\"1\") = " + list.remove("1"));//
        //手动装箱
        System.out.println("list.remove((Integer) 300) = " + list.remove(Integer.valueOf(300)));
        System.out.println("list.remove(1) = " + list.remove(1));//
        System.out.println("list = " + list);//
        System.out.println("list.size() = " + list.size());//

        System.out.println("Arrays.toString(list.toArray()) = " + Arrays.toString(list.toArray()));

        //
        for (int i = 0; i < list.size() ; i++) {
            System.out.println(list.get(i));
        }
        //
        for (int i:list
             ) {
            System.out.println(i);
        }
        //
        Iterator<Integer> it= list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        //
        ListIterator<Integer> it2= list.listIterator();
        while (it2.hasNext()){
            System.out.println(it2.next());
        }

    }
}
